//
//  ProgressView.swift
//  CXSwiftWB
//
//  Created by meidaeriOS on 2017/6/12.
//  Copyright © 2017年 meidaer. All rights reserved.
//

import UIKit

class ProgressView: UIView {

    /// 进度 0 ~ 1
    var progress: CGFloat = 0.0 {
        didSet {
            setNeedsDisplay()
        }
    }
    
    override func draw(_ rect: CGRect) {
        if progress >= 1.0 {
            return
        }
        
        let center = CGPoint(x: bounds.width * 0.5, y: bounds.height * 0.5)
        
        let radious = min(bounds.width / 2, bounds.height / 2)
        
        let startAngle = -CGFloat(Double.pi / 2)
        
        let endAngle = startAngle + CGFloat(Double.pi * 2) * progress
        
        let beziPath = UIBezierPath(arcCenter: center, radius: radious, startAngle:startAngle, endAngle:endAngle, clockwise: true)
        
        UIColor.lightGray.set()
        
        beziPath.addLine(to: center)
        
        beziPath.close()
        
        beziPath.fill()
    }

}
